import xml.etree.ElementTree as ET  
import xml.dom.minidom as minidom


f = open('YDXJ0013.txt')

while (1) : 

    lines = f.readline()

    lines = lines + ' '

    flag = 0
    flag_his = 0
    flag_temp = 0
    line1 = []


    for list in lines:

        if list == ' ':

            line1.append(lines[flag_his:flag])
            flag += 1
            flag_his = flag
            continue      
    
        flag += 1

    line1[9]=line1[9][1:-1]

    line_final = line1[0:10]

    #print (line_final)

    if line_final[6] == '1':
        continue
    path = " "
    if len(line_final[5]) in range(1,2):
        path = "G:\\Lab need\\Dataset\\Varified Data\\Varified_xml\\val_000"+line_final[5]+".xml"
    if len(line_final[5]) in range(2,3):
        path = "G:\\Lab need\\Dataset\\Varified Data\\Varified_xml\\val_00"+line_final[5]+".xml"
    if len(line_final[5]) in range(3,4):
        path = "G:\\Lab need\\Dataset\\Varified Data\\Varified_xml\\val_0"+line_final[5]+".xml"
    if len(line_final[5]) in range(4,5):
        path = "G:\\Lab need\\Dataset\\Varified Data\\Varified_xml\\val_"+line_final[5]+".xml"
    
    tree = ET.parse(path)
    root = tree.getroot()
    object1 = ET.SubElement(root,"object")
    name = ET.SubElement(object1,"name")
    if line_final[9] == "scallop\"" or line_final[9] == "seaurchin\"" or line_final[9] == "seacucumber\"":
        name.text = line_final[9][0:-1]
    else:
        if line_final[9] == "scallo" or line_final[9] == "seaurchi" or line_final[9] == "seacucumbe":
            name.text = line_final[9]
        else:
            name.text = line_final[9]

    pose = ET.SubElement(object1,"pose")
    truncated = ET.SubElement(object1,"truncated")
    Difficult = ET.SubElement(object1,"Difficult")
    bndbox = ET.SubElement(object1,"bndbox")
    pose.text = "Unspecified"
    truncated.text = "0"
    Difficult.text = "0"
    xmin = ET.SubElement(bndbox,"xmin")
    ymin = ET.SubElement(bndbox,"ymin")
    xmax = ET.SubElement(bndbox,"xmax")
    ymax = ET.SubElement(bndbox,"ymax")
    xmin.text = line_final[1]
    ymin.text = line_final[2]
    xmax.text = line_final[3]
    ymax.text = line_final[4]

    tree.write(path,'utf-8',True)

